<section id="content">
    <div class="page page-fullwidth-layout">

        <div class="pageheader">

            <div class="page-bar">

                <ul class="page-breadcrumb">
                    <li>
                        <a href="{:url('/admin')}"><i class="fa fa-home"></i> 起始页</a>
                    </li>
                    <li>
                        <a href="#">信息公告</a>
                    </li>
                </ul>

            </div>
        </div>
        <!-- page content -->
        <div class="pagecontent">
            <div class="box-header">
                <h3 class="box-title">公告列表</h3>
            </div>
            <!-- row -->
            <div class="row">
                <!-- col -->
                <div class="col-md-12">
                    <!-- tile -->
                    <section class="tile">
                        <!-- tile body -->
                        <div class="tile-header dvd dvd-btm" style="margin:-10px 0 20px 0">
                            <ul class="controls addnotice">
                                <li><a href="javascript:void(0)"><i class="fa fa-plus mr-5"></i> 新增</a></li>
                            </ul>
                        </div>

                        <div class="tile-body">
                            <div class="alert alert-info" style="display:none;">显示一些提示信息</div>

                            <div class="table-responsive">
                                <table id="list-table" class="table table-bordered table-striped dataTable">
                                    <thead>
                                        <tr role="row" align="center">
                                            <th>ID</th>
                                            <th>公告标题</th>
                                            <th>发布人</th>
                                            <th>发布时间</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                    {volist name='notice' id='item'}
                                        <tr id="tr_{$item['notice_id']}" align="center">
                                            <td>{$item.notice_id}</td>
                                            <td>{$item.no_title}</td>
                                            <td>{$item.nickname}</td>
                                            <td>{$item.addtime|date='Y-m-d H:i:s',###}</td>
                                            <td>
                                                <a class="btn btn-info noticedetail" notice_id="{$item['notice_id']}" href="javascript:void(0)">
                                                    <i class="glyphicon glyphicon-edit icon-white"></i>
                                                    详情
                                                </a>
                                                <a class="btn btn-danger" href="javascript:void(0);"  onclick="if(confirm('确定要删除该公告吗')){ deleteData({$item['notice_id']})}">
                                                    <i class="glyphicon glyphicon-trash icon-white"></i>
                                                    删除
                                                </a>
                                            </td>
                                        </tr>
                                    {/volist}

                                    </tbody>
                                    <tfoot>

                                    </tfoot>
                                </table>
                            </div>
                            <div class="text-center"></div>
                        </div>
                        <!-- /tile body -->
                    </section>
                    <!-- /tile -->
                </div>
                <!-- /col -->
            </div>
            <!-- /row -->
        </div>
        <!-- /page content -->
    </div>
    <script type="text/javascript">
        function deleteData(notice_id){
            $.ajax({
                type:"get",
                data: {'notice_id':notice_id},
                url:"{:url($data.module_url.'delete')}",
                success:function(data){
                    if(data.error == 0){
                        $('#tr_'+data.notice_id).remove();
                    }
                    $('.alert').html(data.msg).show();
                    setTimeout(function() {
                        $('.alert').hide();
                    }, 3000);
                },
                error:function(data){

                }
            });
        }
        $('.addnotice').click(function(){
            $('#myModal1').modal('show');
        })

        function checkform1(){
            var no_title = document.getElementById("no_title").value;
            var no_desc = document.getElementById("no_desc").value;
            if(!no_title){
                alert("公告标题不能为空");
                return false;
            }
            if(!no_desc){
                alert("公告详情不能为空");
                return false;
            }
            document.getElementById("myform1").submit();
        }

        $('.noticedetail').click(function(){
            var notice_id = $(this).attr('notice_id');
            $('#notice_id').val(notice_id);
            $.ajax({
                type : "get",
                url:"{:url($data.module_url.'noticedetail')}",
                data : {'notice_id':notice_id},
                success: function(data){
                    $('#detail_no_title').val(data.no_title);
                    $('#detail_no_desc').val(data.no_desc);

                    $('#myModal2').modal('show');
                },
                errror:function(data){
                    alert('服务器错误！');
                }
            });
        })

        function checkform2(){
            var detail_no_title = document.getElementById("detail_no_title").value;
            var detail_no_desc = document.getElementById("detail_no_desc").value;
            if(!detail_no_title){
                alert("公告标题不能为空");
                return false;
            }
            if(!detail_no_desc){
                alert("公告详情不能为空1");
                return false;
            }
            document.getElementById("myform2").submit();
        }
    </script>
</section>
<!-- 模态框（Modal）新增 -->
<div class="modal fade" id="myModal1"  tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">新增公告</h4>
            </div>
            <div class="modal-body">
                <form id="myform1" action="{:url($data.module_url).'create'}" method="post">
                    <table>
                        <tr>
                            <td>
                                公告标题：
                            </td>
                            <td>
                                <input type="text" id="no_title" name="no_title" value=""/>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                公告详情：
                            </td>
                            <td>
                                <textarea id="no_desc" name="no_desc" class="form-control" rows="15" cols="15" style="width:300px"></textarea>
                            </td>
                        </tr>
                    </table>
                </form>

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="checkform1()">提交</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

<!-- 模态框（Modal）修改 -->
<div class="modal fade" id="myModal2"  tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">查看公告</h4>
            </div>
            <div class="modal-body">
                <form id="myform2" action="{:url($data.module_url).'upNotice'}" method="post">
                    <input type="hidden" name="notice_id" id="notice_id" value=""/>
                    <table>
                        <tr>
                            <td>
                                公告标题：
                            </td>
                            <td>
                                <input type="text" id="detail_no_title" name="no_title" value=""/>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                公告详情：
                            </td>
                            <td>
                                <textarea id="detail_no_desc" name="no_desc" class="form-control" rows="15" cols="15" style="width:300px"></textarea>
                            </td>
                        </tr>
                    </table>
                </form>

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="checkform2()">提交</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>


